$(function () {
    vm.query();
});


var vm = new Vue({
	el:'#rrapp',
	data:{
        showList: true,
		shelvesgroup: {}
	},
	methods: {
		query: function () {
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/shelvesgroup/alllist",
                success: function(r){
                    if(r.alllist!=null){
                        var temp = '';
                        for(var i=0;i<r.alllist.length;i++){
                            temp +="<div style='box-sizing: border-box;width: 470px;height: 200px;" +
                                "background: #fff;border: 1px solid #e2e5ed;border-radius: 3px;" +
                                "cursor: pointer;float: left;margin-top: 10px!important;margin-right: 10px;'>" +
                                "<div style='box-sizing: border-box;margin: 0 20px;" +
                                "padding: 30px 0;border-bottom: 1px solid #E2E5ED;line-height:1!important;'>" +
                                "<p style='font-size:20px!important;'>"+r.alllist[i].groupname+"</p><p style='font-size:12px;margin-top: 10px!important;'>货架总数</p>" +
                                "<p style='font-size: 24px;margin: 0!important;'>"+r.alllist[i].shelvescount+"</p></div>" +
								"<div style='box-sizing: border-box;margin: 0 20px;height:50px;line-height:50px;display:block;clear:both;'>" +
                                "<span style='float:left;' onclick='vm.update("+r.alllist[i].id+")'><img src='../../statics/img/ico14-edit-black.png' width='14' height='14' style='margin-right:5px;margin-top: -3px;'/>编辑</span>" +
                                "<span style='float:right' onclick='vm.del("+r.alllist[i].id+")'><img src='../../statics/img/ico16-delete.png' width='14' height='14' style='margin-right:5px;margin-top: -3px;'/>删除</span></div></div>";
                        }
                        $("#jqGrid").html(temp);
                    }

                }
            });
		},
		add: function(){
			vm.showList = true;
			vm.shelvesgroup = {};
            $("#myModalLabel").text("新增货架分组");
            $('#myModal').modal();
		},
		update: function (id) {
            
            vm.getInfo(id);
            $("#myModalLabel").text("修改货架分组");
            $('#myModal').modal();
		},
		saveOrUpdate: function (event) {
			var url = vm.shelvesgroup.id == null ? "sys/shelvesgroup/save" : "sys/shelvesgroup/update";
			if(vm.shelvesgroup.groupname == ''|| typeof vm.shelvesgroup.groupname=='undefined'){
				alert("货架名称不能为空！");
			}else{
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.shelvesgroup),
                    success: function(r){
                        if(r.code === 0){
                            alert('操作成功', function(index){
                                vm.query();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
			}

		},
		del: function (id) {
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "sys/shelvesgroup/delete/"+id,
                    contentType: "application/json",
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
                                vm.query();
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "sys/shelvesgroup/info/"+id, function(r){
                vm.shelvesgroup = r.shelvesgroup;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});